import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/collection_util.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/dragView/kq_drag_grid_view.dart';

import '../../resources/Images.dart';

/// 拖拽演示demo - 网格
class DragGridViewDemoPage extends StatefulWidget {
  const DragGridViewDemoPage({Key? key}) : super(key: key);

  @override
  DragGridViewDemoPageState createState() => DragGridViewDemoPageState();
}

class DragGridViewDemoPageState extends State<DragGridViewDemoPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            KqDragGridView(
              columnCount: 4,
              spacing: 1.r,
              padding: 1.r,
              backgroundColor: KqThemeColors.lineColor,
              widgetsBuilder: (widgetSize) {
                return buildWidgets1(widgetSize);
              },
              onDragComplete: (oldIndex, newIndex, children) {
                //交换数据位置
                CollectionUtil.swap(children, oldIndex, newIndex);
              },
            ),
            SizedBox(width: 1, height: 10.r),
            KqDragGridView(
              columnCount: 2,
              spacing: 1.r,
              padding: 1.r,
              backgroundColor: KqThemeColors.lineColor,
              widgetsBuilder: (widgetSize) {
                return buildWidgets2(widgetSize);
              },
              onDragComplete: (oldIndex, newIndex, children) {
                //交换数据位置
                CollectionUtil.swap(children, oldIndex, newIndex);
              },
            )
          ],
        ),
      ),
    );
  }

  buildWidgets1(double widgetSize) {
    return [
      buildWidget1('计划单', widgetSize),
      buildWidget1('任务单', widgetSize),
      buildWidget1('生产报工', widgetSize),
      buildWidget1('次品录入', widgetSize),
      buildWidget1('模具维修', widgetSize),
      buildWidget1('设备维修', widgetSize),
    ];
  }

  Widget buildWidget1(String title, double widgetWidth) {
    return Container(
      color: KqThemeColors.bgWhite,
      width: widgetWidth,
      height: 100.r,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          KqImage.assets(url: Images.demoIcTouxiang),
          SizedBox(
            width: 1.r,
            height: 4.r,
          ),
          Text(
            title,
            style: TextStyle(color: KqThemeColors.text666, fontSize: 14.sp),
          )
        ],
      ),
    );
  }

  buildWidgets2(double widgetSize) {
    return [
      buildWidget2('计划单报表', widgetSize),
      buildWidget2('任务单报表', widgetSize),
      buildWidget2('生产报表', widgetSize),
      buildWidget2('利用率报表', widgetSize),
      buildWidget2('OEE报表', widgetSize),
    ];
  }

  Widget buildWidget2(String title, double widgetWidth) {
    return Container(
      color: KqThemeColors.bgWhite,
      width: widgetWidth,
      height: 100.r,
      padding: EdgeInsets.symmetric(horizontal: 10.r),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          KqImage.assets(url: Images.demoIcTouxiang),
          SizedBox(
            width: 10.r,
            height: 1.r,
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(color: KqThemeColors.text666, fontSize: 14.sp),
              ),
              SizedBox(
                width: 1.r,
                height: 10.r,
              ),
              Text(
                '昨日产出23141个',
                style: TextStyle(color: KqThemeColors.text999, fontSize: 12.sp),
              )
            ],
          )
        ],
      ),
    );
  }
}
